
clear
set more off
capture log close
set seed 12345	
set matsize 10000
set maxvar 20000
global OUTPUT "$DIR/Output"
global DATA "$DIR"	
cd "$DIR"

/* SET LOCALS */
* set earliest tax year to keep
local yrb = 2008
* set last tax year to keep
local yre = 2016
* set excluded base year for event-time and controls
local baseyr "2012"
* set tc sample (ncg nbus)
local ivsamp "ncg"
* average or not ("_avg" or "")
local ivavg ""



**********************************************
**  Prep liability net of business income variables
**********************************************
use "$DATA/scorp_tc_nbus_firm_file.dta", clear
des
drop mtr_firm mtr_2013_firm t2*
ren t1 t1_tc
ren atr_firm atr 
ren atr_ord_firm atr_k1
ren atr_tot_firm atr_tot
ren atr_2013_firm atr_2013
ren atr_ord_2013_firm atr_k1_2013
ren atr_tot_2013_firm atr_tot_2013
ren liab_ord liab_k1
ren liab_ord_2013 liab_k1_2013
drop *k1*

* create top net of business income treatment variable
gen top=t1_tc
forval j=2011/2012 {
foreach v in top {
	gen vv=.
	replace vv = `v' if year==`j'
	bys firm_tin: egen `v'_`j'=max(vv)
	drop vv
}
}
gen tt1112_nbus=.
replace tt1112_nbus = 1 if  top_2011==1 & top_2012==1 
replace tt1112_nbus = 0 if  top_2011==0 & top_2012==0 

* create ATR IV's for elasticity
local linc "atr_tot_2013 atr_tot"
foreach p in `linc' {
	gen ln`p'=ln(`p') if `p' > 0
	replace ln`p'=ln(`p'+((`p'^2)+1)^.5) if `p'<=0
}
gen datr_tot_iv = atr_tot_2013 - atr_tot
gen dlnatr_tot_iv = lnatr_tot_2013 - lnatr_tot
replace dlnatr_tot_iv = 0 if dlnatr_tot_iv<0

foreach v in datr_tot_iv  dlnatr_tot_iv {
	gen zz = 0
	replace zz = `v' if year==2012
	bys firm_tin: egen `v'_2012 = sum(zz)
	drop zz
}

ren liab_tot liab_tot_nbus
ren liab_tot_2013 liab_tot_nbus_2013
ren dlnatr_tot_iv_2012 dlnatr_tot_nbus_iv_2012
keep firm_tin year tt1112_nbus liab_tot_nbus liab_tot_nbus_2013 dlnatr_tot_nbus_iv_2012
sort firm_tin year
tempfile ttt
save `ttt', replace


******
**  merge onto main sample and prep
******
use $DATA/reg_file_firm, clear

sort firm_tin year
merge 1:1 firm_tin year using `ttt'
tab _merge bal_liab
drop _merge

replace tt1112_nbus = . if tt1112==1 & tt1112_nbus==0
replace tt1112_nbus = . if tt1112==0 & tt1112_nbus==1

* Create change in liability variables
foreach j in liab_tot_nbus liab_tot_nbus_2013 {
	gen pw`j' = `j'/n_ft_lower
	replace pw`j' = `j' if n_ft_lower==0
}
gen dliab_tot_nbus_iv = liab_tot_nbus_2013 - liab_tot_nbus
gen dpwliab_tot_nbus_iv = pwliab_tot_nbus_2013 - pwliab_tot_nbus

* create firm-level IV variables
foreach v in  dliab_tot_nbus_iv dpwliab_tot_nbus_iv {
	gen zz = 0
	replace zz = `v' if year==2012
	bys firm_tin: egen `v'_2012 = sum(zz)
	drop zz
}


************************************************************************************************
************************************************************************************************
**  Single owner  [Figure A.8, Table A.9]
************************************************************************************************
************************************************************************************************

local bm1 = `baseyr'-1
local bp1 = `baseyr'+1
local r1 "i.netinc_`baseyr'cat##ib`baseyr'.year i.naics_`baseyr'##ib`baseyr'.year i.cz_`baseyr'##ib`baseyr'.year"

local tt "tt1112_ncg"
local t "dpwliab_tot_iv_2012"
forval y = `yrb' / `yre' {
	drop t`y'
	gen t`y' = 0
	replace t`y' = . if `t'==.
	replace t`y' = `t' if year==`y' & `tt'==1
}
* base 2011,2012
local events "t`yrb'-t2010 t`bp1'-t`yre' y`yrb'-y2010 y`bp1'-y`yre' `t'"

************
**  reduced form - all [Figure A.8, Panel A]
************
foreach r in 1 {
	eststo r`r': quietly reghdfe dwages_ft `events'  [aw=n_ft_lower_2012] if (`tt'==1 | `tt'==0) & bal_liab==1 & own1==1, absorb(`r`r'' firm_tin) vce(cluster firm_tin)
}
esttab using "$OUTPUT/figure_A8_panelA.csv", replace se ar2 mtitles( ) keep(t20*) addnote("Each specification includes a different set of control variabels")
eststo clear

* dd version for table [Table A.9, ITT]
drop dd
gen dd=`t'*post
local dr1 "i.netinc_`baseyr'cat##i.post i.naics_`baseyr'##i.post i.cz_`baseyr'##i.post"
local events "`t' post dd"

foreach r in 1 {
	eststo r`r': quietly reghdfe dwages_ft `events'  [aw=n_ft_lower_2012] if (`tt'==1 | `tt'==0) & bal_liab==1  & year>=2011  & own1==1, absorb(`dr`r'' firm_tin) vce(cluster firm_tin)
}
esttab using "$OUTPUT/table_A9_single_itt.csv", replace se ar2 mtitles( ) keep(dd) addnote("Each specification includes a different set of control variabels")
eststo clear

************
**  reduced form - top only [Figure A.8, Panel B]
************
local tt "tt1112_ncg"
local t "dpwliab_tot_iv_2012"
forval y = `yrb' / `yre' {
	drop t`y'
	gen t`y' = 0
	replace t`y' = . if `t'==.
	replace t`y' = `t' if year==`y' & `tt'==1
}
local events "t`yrb'-t2010 t`bp1'-t`yre' y`yrb'-y2010 y`bp1'-y`yre' `t'"

foreach r in 1 {
	eststo r`r': quietly reghdfe dwages_ft `events'  [aw=n_ft_lower_2012] if `tt'==1 & bal_liab==1 & own1==1, absorb(`r`r'' firm_tin) vce(cluster firm_tin)
}
esttab using "$OUTPUT/figure_A8_panelB.csv", replace se ar2  mtitles( ) keep(t20*) addnote("Each specification includes a different set of control variabels")
eststo clear

************
**  first stage - yearly [Figure A.8, Panel C]
************
local t "tt1112_ncg"
forval y = `yrb' / `yre' {
	drop t`y'
	gen t`y' = 0
	replace t`y' = . if `t'==.
	replace t`y' = `t' if year==`y'
}
* base 2011,2012
local events "t`yrb'-t2010 t`bp1'-t`yre' y`yrb'-y2010 y`bp1'-y`yre' `t'"

eststo fs: quietly reg liab_tot `events'  if (`t'==1 | `t'==0) & bal_liab==1 & year>=2011 & own1==1
esttab using "$OUTPUT/figure_A8_panelC.csv", replace se ar2 scalar(F) mtitles( ) keep(t2013 t2014 t2015 t2016) 
eststo clear

******
**  Predicted stat [Figure A.8, panel C]
******
sum dliab_tot_iv_2012 if dliab_tot_iv_2012>0 & year==2012 & bal_liab==1 & own1==1,d
* $29741.69

************
**  2sls - dd [Table A.9, 2SLS]
************
local tt "tt1112_ncg"
drop dd
gen dd=`tt'*post
local dr1 "i.valaddpw_ft_2012cat##i.post i.netinc_`baseyr'cat##i.post i.naics_`baseyr'##i.post i.cz_`baseyr'##i.post"
local events "`tt' post dd"

* first stage
foreach r in 1 {
	quietly reg liab_tot `events' `dr`r'' if (`tt'==1 | `tt'==0) & year>=2011 & bal_liab==1 & own1==1
	predict yhatdd`r',xb
}
* F-Stat 
di e(F) 
* F-Stat = 174.4

* 2sls
foreach r in 1 {
	local t "yhatdd`r'"
	drop dd
	gen dd=`t'*post
	local events "`t' post dd"

	eststo w99_r`r': quietly reg dwwagebill_ft99 `events' `dr`r'' if (`tt'==1 | `tt'==0) & year>=2011 & bal_liab==1 & own1==1, vce(cluster firm_tin)
}
esttab using "$OUTPUT/table_A9_single_2sls.csv", replace se ar2 mtitles( ) keep(dd) 
eststo clear
drop yhat* 

**************
**  Elasticity - ATR [Table A.9, elasticity]
**************
local trt "tt1112_ncg"
local t "dlnatr_tot_iv_2012"
forval y = `yrb' / `yre' {
	drop t`y'
	gen t`y' = 0
	replace t`y' = . if `t'==.
	replace t`y' = `t' if year==`y'
}
local events "t`yrb'-t2010 t`bp1'-t`yre' y`yrb'-y2010 y`bp1'-y`yre' `t'"

* loop over regressions
foreach r in 1 {
	eststo r`r': quietly reghdfe lnwages_ft `events'  [aw=n_ft_lower_2012] if (`trt'==1 | `trt'==0)  & bal_liab==1 & (year==2011 | year==2012 | year==2016) & own1==1, absorb(`r`r'' firm_tin) vce(cluster firm_tin)
}
esttab using "$OUTPUT/table_A9_single_elasticity.csv", replace se ar2 mtitles( ) keep(t2016) 
eststo clear





************************************************************************************************
************************************************************************************************
**  Robust - avg 2011-2012  [Figure A.7, Table A.9]
************************************************************************************************
************************************************************************************************
local bm1 = `baseyr'-1
local bp1 = `baseyr'+1
local r1 "i.netinc_`baseyr'cat##ib`baseyr'.year i.naics_`baseyr'##ib`baseyr'.year i.cz_`baseyr'##ib`baseyr'.year"

local tt "tt1112_ncg"
local t "dpwmliab_tot_iv_2012"
forval y = `yrb' / `yre' {
	drop t`y'
	gen t`y' = 0
	replace t`y' = . if `t'==.
	replace t`y' = `t' if year==`y' & `tt'==1
}
* base 2011,2012
local events "t`yrb'-t2010 t`bp1'-t`yre' y`yrb'-y2010 y`bp1'-y`yre' `t'"

************
**  reduced form - all [Figure A.7]
************
foreach r in 1 {
	eststo r`r': quietly reghdfe dwages_ft `events'  [aw=n_ft_lower_2012] if (`tt'==1 | `tt'==0) & bal_liab==1, absorb(`r`r'' firm_tin) vce(cluster firm_tin)
}
esttab using "$OUTPUT/figure_A7_avg.csv", replace se ar2 mtitles( ) keep(t20*) addnote("Each specification includes a different set of control variabels")
eststo clear

* dd version for table [Table A.9, ITT]
drop dd
gen dd=`t'*post
local dr1 "i.netinc_`baseyr'cat##i.post i.naics_`baseyr'##i.post i.cz_`baseyr'##i.post"
local events "`t' post dd"

foreach r in 1 {
	eststo r`r': quietly reghdfe dwages_ft `events'  [aw=n_ft_lower_2012] if (`tt'==1 | `tt'==0) & bal_liab==1  & year>=2011, absorb(`dr`r'' firm_tin) vce(cluster firm_tin)
}
esttab using "$OUTPUT/table_A9_avg_itt.csv", replace se ar2 mtitles( ) keep(dd) addnote("Each specification includes a different set of control variabels")
eststo clear

************
**  2sls - dd [Table A.9, 2SLS]
************
local tt "tt1112_ncg"
drop dd
gen dd=`tt'*post
local dr1 "i.valaddpw_ft_2012cat##i.post i.netinc_`baseyr'cat##i.post i.naics_`baseyr'##i.post i.cz_`baseyr'##i.post"
local events "`tt' post dd"

* first stage
foreach r in 1 {
	quietly reg mliab_tot `events' `dr`r'' if (`tt'==1 | `tt'==0) & year>=2011 & bal_liab==1 
	predict yhatdd`r',xb
}

* 2sls
foreach r in 1 {
	local t "yhatdd`r'"
	drop dd
	gen dd=`t'*post
	local events "`t' post dd"

	eststo w99_r`r': quietly reg dwwagebill_ft99 `events' `dr`r'' if (`tt'==1 | `tt'==0) & year>=2011 & bal_liab==1, vce(cluster firm_tin)
}
esttab using "$OUTPUT/table_A9_avg_2sls.csv", replace se ar2 mtitles( ) keep(dd) 
eststo clear
drop yhat* 

**************
**  Elasticity - ATR [Table A.9, elasticity]
**************
local trt "tt1112_ncg"
local t "dlnmatr_tot_iv_2012"
forval y = `yrb' / `yre' {
	drop t`y'
	gen t`y' = 0
	replace t`y' = . if `t'==.
	replace t`y' = `t' if year==`y'
}
local events "t`yrb'-t2010 t`bp1'-t`yre' y`yrb'-y2010 y`bp1'-y`yre' `t'"

* loop over regressions
foreach r in 1 {
	eststo r`r': quietly reghdfe lnwages_ft `events'  [aw=n_ft_lower_2012] if (`trt'==1 | `trt'==0)  & bal_liab==1 & (year==2011 | year==2012 | year==2016), absorb(`r`r'' firm_tin) vce(cluster firm_tin)
}
esttab using "$OUTPUT/table_A9_avg_elasticity.csv", replace se ar2 mtitles( ) keep(t2016) 
eststo clear




************************************************************************************************
************************************************************************************************
**  Robust - k1  [Figure A.7, Table A.9]
************************************************************************************************
************************************************************************************************
local bm1 = `baseyr'-1
local bp1 = `baseyr'+1
local r1 "i.netinc_`baseyr'cat##ib`baseyr'.year i.naics_`baseyr'##ib`baseyr'.year i.cz_`baseyr'##ib`baseyr'.year"

local tt "tt1112_ncg"
local t "dpwliab_k1_iv_2012"
forval y = `yrb' / `yre' {
	drop t`y'
	gen t`y' = 0
	replace t`y' = . if `t'==.
	replace t`y' = `t' if year==`y' & `tt'==1
}
* base 2011,2012
local events "t`yrb'-t2010 t`bp1'-t`yre' y`yrb'-y2010 y`bp1'-y`yre' `t'"

************
**  reduced form - all [Figure A.7]
************
foreach r in 1 {
	eststo r`r': quietly reghdfe dwages_ft `events'  [aw=n_ft_lower_2012] if (`tt'==1 | `tt'==0) & bal_liab==1, absorb(`r`r'' firm_tin) vce(cluster firm_tin)
}
esttab using "$OUTPUT/figure_A7_k1.csv", replace se ar2 mtitles( ) keep(t20*) addnote("Each specification includes a different set of control variabels")
eststo clear

* dd version for table [Table A.9, ITT]
drop dd
gen dd=`t'*post
local dr1 "i.netinc_`baseyr'cat##i.post i.naics_`baseyr'##i.post i.cz_`baseyr'##i.post"
local events "`t' post dd"

foreach r in 1 {
	eststo r`r': quietly reghdfe dwages_ft `events'  [aw=n_ft_lower_2012] if (`tt'==1 | `tt'==0) & bal_liab==1  & year>=2011, absorb(`dr`r'' firm_tin) vce(cluster firm_tin)
}
esttab using "$OUTPUT/table_A9_k1_itt.csv", replace se ar2 mtitles( ) keep(dd) addnote("Each specification includes a different set of control variabels")
eststo clear

************
**  2sls - dd [Table A.9, 2SLS]
************
local tt "tt1112_ncg"
drop dd
gen dd=`tt'*post
local dr1 "i.valaddpw_ft_2012cat##i.post i.netinc_`baseyr'cat##i.post i.naics_`baseyr'##i.post i.cz_`baseyr'##i.post"
local events "`tt' post dd"

* first stage
foreach r in 1 {
	quietly reg liab_k1 `events' `dr`r'' if (`tt'==1 | `tt'==0) & year>=2011 & bal_liab==1 
	predict yhatdd`r',xb
}

* 2sls
foreach r in 1 {
	local t "yhatdd`r'"
	drop dd
	gen dd=`t'*post
	local events "`t' post dd"

	eststo w99_r`r': quietly reg dwwagebill_ft99 `events' `dr`r'' if (`tt'==1 | `tt'==0) & year>=2011 & bal_liab==1, vce(cluster firm_tin)
}
esttab using "$OUTPUT/table_A9_k1_2sls.csv", replace se ar2 mtitles( ) keep(dd) 
eststo clear
drop yhat* 

**************
**  Elasticity - ATR [Table A.9, elasticity]
**************
local trt "tt1112_ncg"
local t "dlnatr_k1_iv_2012"
forval y = `yrb' / `yre' {
	drop t`y'
	gen t`y' = 0
	replace t`y' = . if `t'==.
	replace t`y' = `t' if year==`y'
}
local events "t`yrb'-t2010 t`bp1'-t`yre' y`yrb'-y2010 y`bp1'-y`yre' `t'"

* loop over regressions
foreach r in 1 {
	eststo r`r': quietly reghdfe lnwages_ft `events'  [aw=n_ft_lower_2012] if (`trt'==1 | `trt'==0)  & bal_liab==1 & (year==2011 | year==2012 | year==2016), absorb(`r`r'' firm_tin) vce(cluster firm_tin)
}
esttab using "$OUTPUT/table_A9_k1_elasticity.csv", replace se ar2 mtitles( ) keep(t2016) 
eststo clear




************************************************************************************************
************************************************************************************************
**  Robust - nbus   [Figure A.7, Table A.9]
************************************************************************************************
************************************************************************************************
local bm1 = `baseyr'-1
local bp1 = `baseyr'+1
local r1 "i.netinc_`baseyr'cat##ib`baseyr'.year i.naics_`baseyr'##ib`baseyr'.year i.cz_`baseyr'##ib`baseyr'.year"

local tt "tt1112_nbus"
local t "dpwliab_tot_nbus_iv_2012"
forval y = `yrb' / `yre' {
	drop t`y'
	gen t`y' = 0
	replace t`y' = . if `t'==.
	replace t`y' = `t' if year==`y' & `tt'==1
}
* base 2011,2012
local events "t`yrb'-t2010 t`bp1'-t`yre' y`yrb'-y2010 y`bp1'-y`yre' `t'"

************
**  reduced form - all [Figure A.7]
************
foreach r in 1 {
	eststo r`r': quietly reghdfe dwages_ft `events'  [aw=n_ft_lower_2012] if (`tt'==1 | `tt'==0) & bal_liab==1, absorb(`r`r'' firm_tin) vce(cluster firm_tin)
}
esttab using "$OUTPUT/figure_A7_nbus.csv", replace se ar2 mtitles( ) keep(t20*) addnote("Each specification includes a different set of control variabels")
eststo clear

* dd version for table [Table A.9, ITT]
drop dd
gen dd=`t'*post
local dr1 "i.netinc_`baseyr'cat##i.post i.naics_`baseyr'##i.post i.cz_`baseyr'##i.post"
local events "`t' post dd"

foreach r in 1 {
	eststo r`r': quietly reghdfe dwages_ft `events'  [aw=n_ft_lower_2012] if (`tt'==1 | `tt'==0) & bal_liab==1  & year>=2011, absorb(`dr`r'' firm_tin) vce(cluster firm_tin)
}
esttab using "$OUTPUT/table_A9_nbus_itt.csv", replace se ar2 mtitles( ) keep(dd) addnote("Each specification includes a different set of control variabels")
eststo clear

************
**  2sls - dd [Table A.9, 2SLS]
************
local tt "tt1112_nbus"
drop dd
gen dd=`tt'*post
local dr1 "i.valaddpw_ft_2012cat##i.post i.netinc_`baseyr'cat##i.post i.naics_`baseyr'##i.post i.cz_`baseyr'##i.post"
local events "`tt' post dd"

* first stage
foreach r in 1 {
	quietly reg liab_tot_nbus `events' `dr`r'' if (`tt'==1 | `tt'==0) & year>=2011 & bal_liab==1 
	predict yhatdd`r',xb
}

* 2sls
foreach r in 1 {
	local t "yhatdd`r'"
	drop dd
	gen dd=`t'*post
	local events "`t' post dd"

	eststo w99_r`r': quietly reg dwwagebill_ft99 `events' `dr`r'' if (`tt'==1 | `tt'==0) & year>=2011 & bal_liab==1, vce(cluster firm_tin)
}
esttab using "$OUTPUT/table_A9_nbus_2sls.csv", replace se ar2 mtitles( ) keep(dd) 
eststo clear
drop yhat* 

**************
**  Elasticity - ATR [Table A.9, elasticity]
**************
local trt "tt1112_nbus"
local t "dlnatr_tot_nbus_iv_2012"
forval y = `yrb' / `yre' {
	drop t`y'
	gen t`y' = 0
	replace t`y' = . if `t'==.
	replace t`y' = `t' if year==`y'
}
local events "t`yrb'-t2010 t`bp1'-t`yre' y`yrb'-y2010 y`bp1'-y`yre' `t'"

* loop over regressions
foreach r in 1 {
	eststo r`r': quietly reghdfe lnwages_ft `events'  [aw=n_ft_lower_2012] if (`trt'==1 | `trt'==0)  & bal_liab==1 & (year==2011 | year==2012 | year==2016), absorb(`r`r'' firm_tin) vce(cluster firm_tin)
}
esttab using "$OUTPUT/table_A9_nbus_elasticity.csv", replace se ar2 mtitles( ) keep(t2016) 
eststo clear




************************************************************************************************
************************************************************************************************
**  Exclude top 0.1% - liab_tot  [Figure A.7, Table A.9]
************************************************************************************************
************************************************************************************************
replace top01_all = 0 if top01==0

local bm1 = `baseyr'-1
local bp1 = `baseyr'+1
local r1 "i.netinc_`baseyr'cat##ib`baseyr'.year i.naics_`baseyr'##ib`baseyr'.year i.cz_`baseyr'##ib`baseyr'.year"

local tt "tt1112_ncg"
local t "dpwliab_tot_iv_2012"
forval y = `yrb' / `yre' {
	drop t`y'
	gen t`y' = 0
	replace t`y' = . if `t'==.
	replace t`y' = `t' if year==`y' & `tt'==1
}
* base 2011,2012
local events "t`yrb'-t2010 t`bp1'-t`yre' y`yrb'-y2010 y`bp1'-y`yre' `t'"

************
**  reduced form - all [Figure A.7]
************
foreach r in 1 {
	eststo r`r': quietly reghdfe dwages_ft `events'  [aw=n_ft_lower_2012] if (`tt'==1 | `tt'==0) & bal_liab==1 & top01_all==0, absorb(`r`r'' firm_tin) vce(cluster firm_tin)
}
esttab using "$OUTPUT/figure_A7_top01.csv", replace se ar2 mtitles( ) keep(t20*) addnote("Each specification includes a different set of control variabels")
eststo clear

* dd version for table [Table A.9, ITT]
drop dd
gen dd=`t'*post
local dr1 "i.netinc_`baseyr'cat##i.post i.naics_`baseyr'##i.post i.cz_`baseyr'##i.post"
local events "`t' post dd"

foreach r in 1 {
	eststo r`r': quietly reghdfe dwages_ft `events'  [aw=n_ft_lower_2012] if (`tt'==1 | `tt'==0) & bal_liab==1 & year>=2011 & top01_all==0, absorb(`dr`r'' firm_tin) vce(cluster firm_tin)
}
esttab using "$OUTPUT/table_A9_top01_itt.csv", replace se ar2 mtitles( ) keep(dd) addnote("Each specification includes a different set of control variabels")
eststo clear

************
**  2sls - dd [Table A.9, 2SLS]
************
local tt "tt1112_ncg"
drop dd
gen dd=`tt'*post
local dr1 "i.valaddpw_ft_2012cat##i.post i.netinc_`baseyr'cat##i.post i.naics_`baseyr'##i.post i.cz_`baseyr'##i.post"
local events "`tt' post dd"

* first stage
foreach r in 1 {
	quietly reg liab_tot `events' `dr`r'' if (`tt'==1 | `tt'==0) & year>=2011 & bal_liab==1 & top01_all==0
	predict yhatdd`r',xb
}

* 2sls
foreach r in 1 {
	local t "yhatdd`r'"
	drop dd
	gen dd=`t'*post
	local events "`t' post dd"

	eststo w99_r`r': quietly reg dwwagebill_ft99 `events' `dr`r'' if (`tt'==1 | `tt'==0) & year>=2011 & bal_liab==1 & top01_all==0, vce(cluster firm_tin)
}
esttab using "$OUTPUT/table_A9_top01_2sls.csv", replace se ar2 mtitles( ) keep(dd) 
eststo clear
drop yhat* 

**************
**  Elasticity - ATR [Table A.9, elasticity]
**************
local trt "tt1112_ncg"
local t "dlnatr_tot_iv_2012"
forval y = `yrb' / `yre' {
	drop t`y'
	gen t`y' = 0
	replace t`y' = . if `t'==.
	replace t`y' = `t' if year==`y'
}
local events "t`yrb'-t2010 t`bp1'-t`yre' y`yrb'-y2010 y`bp1'-y`yre' `t'"

* loop over regressions
foreach r in 1 {
	eststo r`r': quietly reghdfe lnwages_ft `events'  [aw=n_ft_lower_2012] if (`trt'==1 | `trt'==0)  & bal_liab==1 & (year==2011 | year==2012 | year==2016) & top01_all==0, absorb(`r`r'' firm_tin) vce(cluster firm_tin)
}
esttab using "$OUTPUT/table_A9_top01_elasticity.csv", replace se ar2 mtitles( ) keep(t2016) 
eststo clear









clear
exit
exit




